package com.ruoyi.wms.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.wms.dto.QualityInspectionDto;
import com.ruoyi.wms.vo.QualityInspectionVo;
import com.ruoyi.wms.vo.QualityInspectionVo2;
import com.ruoyi.wms.vo.QualityInspectionVo3;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.wms.domain.QualityInspection;
import com.ruoyi.wms.service.IQualityInspectionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 车辆质检Controller
 *
 * @author libancang
 * @date 2025-10-22
 */
@Api(value = "车辆质检Controller", tags = "车辆质检Controller")
@RestController
@RequestMapping("/inspection")
public class QualityInspectionController extends BaseController {
    @Autowired
    private IQualityInspectionService qualityInspectionService;

    /**
     * 查询车辆质检列表
     */
    @RequiresPermissions("wms:inspection:list")
    @GetMapping("/list")
    public TableDataInfo list(QualityInspectionDto qualityInspection) {
        startPage();
        List<QualityInspectionVo> list = qualityInspectionService.selectQualityInspectionList(qualityInspection);
        return getDataTable(list);
    }


    /**
     * 获取车辆质检详细信息
     */
    @RequiresPermissions("wms:inspection:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(qualityInspectionService.selectQualityInspectionById(id));
    }


    /**
     * 修改车辆质检
     */
    @RequiresPermissions("wms:inspection:edit")
    @Log(title = "车辆质检", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QualityInspection qualityInspection) {
        return toAjax(qualityInspectionService.updateQualityInspection(qualityInspection));
    }


    @Log(title = "车辆质检item保存", businessType = BusinessType.UPDATE)
    @PostMapping("/save")
    public AjaxResult save(@RequestBody QualityInspectionVo3 vo2) {
        try {
            return toAjax(qualityInspectionService.save(vo2));
        }catch ( Exception e){
            e.printStackTrace();
            return  error("传入格式不对");
        }

    }


    /**
     * 删除车辆质检
     */
    @RequiresPermissions("wms:inspection:remove")
    @Log(title = "车辆质检", businessType = BusinessType.DELETE)


    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody String[] ids) {
        if (ids == null || ids.length == 0) {
            return error("未选中");
        }
        return toAjax(qualityInspectionService.deleteQualityInspectionByIds(ids));
    }

    @ApiOperation("根据质检查车牌。车辆质检getInfoById")
    @GetMapping(value = "/getInfoByplateNo")
    public AjaxResult getInfoByplateNo(@ApiParam(value = "车牌号码", required = true) @RequestParam(value = "plateNo") String plateNo) {
        return success(qualityInspectionService.selectQualityInspectionById(plateNo));
    }
}
